package controllers

import (
"centerServer/compnents"
"centerServer/models"
"encoding/json"
"github.com/astaxie/beego"
"time"
)

type RecoderStarsController struct {
	beego.Controller
}

func (this *RecoderStarsController)Get()  {
	requestInfo := models.RecoderCurrencyRequest{}
	backMsg := models.CreatorBackBase(0, "")
	if err := this.ParseForm(&requestInfo); err != nil {
		//handle error
		backMsg.ReturnCode = -1
		backMsg.Msg = "参数解析错误" + err.Error()
		backData, _ := json.Marshal(backMsg)
		this.Ctx.Output.Body(backData)
		return
	}
	// 检测签名
	checkSignMap := requestInfo.GetSignInfos()
	if compnents.CheckSign(checkSignMap, requestInfo.Sign) == false {
		backMsg.ReturnCode = -1
		backMsg.Msg = "签名错误"
		backData, _ := json.Marshal(backMsg)
		this.Ctx.Output.Body(backData)
		return
	}
	// 构造记录
	recoder := models.RecoderStars{
		UnionId:     requestInfo.UnionId,
		OpenId:      requestInfo.OpenId,
		NickName:    requestInfo.NickName,
		Change:      requestInfo.Change,
		Remind:      requestInfo.Remind,
		Desc:        requestInfo.Desc,
		RecoderTime: time.Time{},
	}
	recoder.WriteToDB()
	backData, _ := json.Marshal(backMsg)
	this.Ctx.Output.Body(backData)
}
